class Customer
{
    static getInstance()
    {
        if(!Customer.instance)
        {
            Customer.instance = new Customer();
        }
        return Customer.instance;
    }

    /**
     * 在地图上显示用户的地理位置
     * @param drivers
     */
    render( customers )
    {

        customers.forEach( function ( value , index) {
               this.showCustomerMarket( value )
        },this)
    }

    /**
     * 初始化显示所有客户的标记
     * @param driver
     */
    showCustomerMarket( customer ){

        //对客户有时间要求的 用label用红色标注出来
        let schedule = customer.ScheduleTime.split('--');

        let waitTime = Number(getHoursFromStringDate(schedule[1])) - Number(getHoursFromStringDate(schedule[0]));
        let style = '';
        let requireTime = false;
        if( waitTime <=3 )
        {
            style="color: red;font-weight:bold";
            requireTime = true;
        }
        let uluru = {lat: Number(customer.lat), lng: Number(customer.lng)};
        let scheduleHtmlString='<span style="'+style+'"> '+customer.ScheduleTime+'</span>';
        let contentString = '<div id="content">'+
            '<div id="siteNotice">'+
            '</div>'+
            '<h1 id="firstHeading" class="firstHeading">'+customer.CustName+'</h1>'+
            '<div id="bodyContent">'+
            '<p><b>Address </b>'+customer.Address+'&nbsp;&nbsp;ScheduleTime:<span style="'+style+'"> '+customer.ScheduleTime+'</span></p>'+
            '</div>'+
            '</div>';
            OBJECT.infowindow[customer.CustID] = new google.maps.InfoWindow({
               content: contentString
           });
        OBJECT.CustomerList[customer.CustID] = new google.maps.Marker({
            position: uluru,
            map: map,
            title: customer.CustName,
            requireTime:requireTime,
            contentString:contentString,
            scheduleHtmlString:scheduleHtmlString
        });

        let obj = OBJECT.CustomerList[customer.CustID];   //浅复制一个对象
        //监听单击事件
        OBJECT.CustomerList[customer.CustID].addListener('click', function() {
            OBJECT.infowindow[customer.CustID].open(map, obj);
        });
        //监听双击事件
        OBJECT.CustomerList[customer.CustID].addListener('oncontextmenu', function() {
            OBJECT.infowindow[customer.CustID].close(map, obj);
            alert("Double Click");
        });
    }

    /**
     * 隐藏客户标记
     */
    hide( routerId ){
        let marker = OBJECT.CustomerList;
        marker.forEach( function ( value ,index ) {
            OBJECT.CustomerList[index].setMap(null);
        })
    }
    /**
     * 显示客户标记
     */
    show( routerId ){
        let marker = OBJECT.CustomerList;
        marker.forEach( function ( value ,index ) {
            OBJECT.CustomerList[index].setMap(map);
        })
    }

    /**
     * 显示客户收货时间
     */
    showScheduleTime()
    {
         for( let index in OBJECT.CustomerList)
         {
             if(OBJECT.CustomerList[index].requireTime){
                 OBJECT.infowindow[index] = new google.maps.InfoWindow({
                     content: OBJECT.CustomerList[index].scheduleHtmlString
                 });
                 new google.maps.event.trigger( OBJECT.CustomerList[index], 'click' );
             }
         }
    }

    /**
     * 隐藏客户收货时间
     */
    hideScheduleTime()
    {

        for( let index in OBJECT.CustomerList)
        {
            OBJECT.infowindow[index].close();
            if(OBJECT.CustomerList[index].requireTime){
                OBJECT.infowindow[index] = new google.maps.InfoWindow({
                    content: OBJECT.CustomerList[index].contentString
                });
                //重新设置对象监听方法
                let obj = OBJECT.CustomerList[index];   //浅复制一个对象
                OBJECT.CustomerList[index].addListener('click', function() {
                    OBJECT.infowindow[index].open(map, obj);
                });

            }
        }
    }

    /**
     * 客户是否禁止了司机配送
     * @param points
     * @param driverId
     * @returns {{isForbid: boolean}}
     */
    driverIsForbid(points , driverId)
    {

          let result={isForbid:false};
          points.forEach( function ( value ) {
                 if(value.frobidDriver!=null && value.forbidDriver!='')    //数据更新后有可能为空字符串
                 {

                       let forbidDriverList = new Set();
                        value.frobidDriver.split(',').forEach(x => forbidDriverList.add(x));
                        if(forbidDriverList.has(driverId)){
                             let driver = Driver.getInstance().getDriverById(driverId);
                             result ={isForbid:true,driverName:driver.nickname}
                        }
                 }
         }, this);
         return result;
    }
}